package com.itgungnir.diyshuo.activity.main_activity;

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.itgungnir.diyshuo.activity.R;
import com.itgungnir.diyshuo.fragment.danpin_fragment.DanPinFragment;
import com.itgungnir.diyshuo.fragment.fenlei_fragment.FenLeiFragment;
import com.itgungnir.diyshuo.fragment.wode_fragment.WoFragment;
import com.itgungnir.diyshuo.fragment.zhinan_fragment.ZhiNanFragment;

/**
 * 用在MainActivity中的Model类
 */
public class MainModel implements MainContract.Model {
    @Override
    public void initFragments(FragmentActivity activity) {
        FragmentManager manager = activity.getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.add(R.id.find_main_ly_fragments, new ZhiNanFragment());
        transaction.commit();
    }

    @Override
    public void changeFragment(FragmentActivity activity, int checkedId) {
        FragmentManager manager = null;
        FragmentTransaction transaction = null;
        switch (checkedId) {
            case R.id.find_main_tabbar_zhinan:
                manager = activity.getSupportFragmentManager();
                transaction = manager.beginTransaction();
                transaction.replace(R.id.find_main_ly_fragments, new ZhiNanFragment());
                transaction.commit();
                break;
            case R.id.find_main_tabbar_danpin:
                manager = activity.getSupportFragmentManager();
                transaction = manager.beginTransaction();
                transaction.replace(R.id.find_main_ly_fragments, new DanPinFragment());
                transaction.commit();
                break;
            case R.id.find_main_tabbar_fenlei:
                manager = activity.getSupportFragmentManager();
                transaction = manager.beginTransaction();
                transaction.replace(R.id.find_main_ly_fragments, new FenLeiFragment());
                transaction.commit();
                break;
            case R.id.find_main_tabbar_wo:
                manager = activity.getSupportFragmentManager();
                transaction = manager.beginTransaction();
                transaction.replace(R.id.find_main_ly_fragments, new WoFragment());
                transaction.commit();
                break;
        }
    }
}